<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>个人中心</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: #f5f7fa;
            min-height: 100vh;
            color: #333;
            font-size: 14px;
            line-height: 1.5;
            margin: 0;
            padding: 0;
        }

        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 20px;
            text-align: center;
            position: relative;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .header h1 {
            font-size: 20px;
            font-weight: 600;
            margin-bottom: 5px;
        }

        .header p {
            font-size: 12px;
            opacity: 0.9;
        }

        .container {
            max-width: 100%;
            margin: 0;
            padding: 0;
        }

        .user-card {
            background: white;
            margin: 20px 15px 15px;
            border-radius: 15px;
            padding: 15px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
            position: relative;
        }

        .user-info {
            padding: 5px 0;
        }

        .user-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 8px;
            padding: 4px 0;
            flex-wrap: wrap;
            gap: 8px;
        }

        .user-row:last-child {
            margin-bottom: 0;
        }

        .user-name {
            font-size: 16px;
            font-weight: 600;
            color: #333;
            flex: 1;
            min-width: 80px;
        }

        .user-phone {
            font-size: 14px;
            color: #667eea;
            font-weight: 700;
            background: rgba(102, 126, 234, 0.1);
            padding: 4px 12px;
            border-radius: 18px;
            white-space: nowrap;
        }

        .user-company {
            font-size: 12px;
            color: #666;
            flex: 2;
            text-align: right;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            min-width: 0;
        }

        .function-blocks {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 12px;
            margin-top: 5px;
            grid-auto-flow: column;
            white-space: nowrap;
        }

        .function-item {
            background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
            border-radius: 12px;
            padding: 16px 12px;
            text-align: center;
            border: 1px solid #e9ecef;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }

        .function-item:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
            border-color: #667eea;
        }

        .function-item:active {
            transform: scale(0.98);
        }

        .function-icon {
            font-size: 24px;
            margin-bottom: 8px;
            display: block;
        }

        .function-title {
            font-size: 14px;
            font-weight: 600;
            color: #333;
            margin-bottom: 4px;
        }

        .function-desc {
            font-size: 11px;
            color: #666;
            line-height: 1.3;
        }

        /* 为每个功能块添加不同的渐变边框 */
        .function-item:nth-child(1) {
            border-top: 3px solid #667eea;
        }

        .function-item:nth-child(2) {
            border-top: 3px solid #56ab2f;
        }

        .function-item:nth-child(3) {
            border-top: 3px solid #f093fb;
        }

        .menu-section {
            margin: 15px;
        }

        .section-title {
            font-size: 16px;
            font-weight: 600;
            color: #333;
            margin-bottom: 12px;
            padding-left: 5px;
        }

        .menu-list {
            background: white;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
        }

        .menu-item {
            display: flex;
            align-items: center;
            padding: 15px 20px;
            border-bottom: 1px solid #f0f0f0;
            cursor: pointer;
            transition: background-color 0.2s ease;
            text-decoration: none;
            color: #333;
        }

        .menu-item:last-child {
            border-bottom: none;
        }

        .menu-item:active {
            background-color: #f8f9fa;
        }

        .menu-icon {
            width: 40px;
            height: 40px;
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 18px;
            margin-right: 15px;
            flex-shrink: 0;
        }

        .menu-icon.blue {
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
        }

        .menu-icon.green {
            background: linear-gradient(135deg, #56ab2f, #a8e6cf);
            color: white;
        }

        .menu-icon.orange {
            background: linear-gradient(135deg, #f093fb, #f5576c);
            color: white;
        }

        .menu-icon.purple {
            background: linear-gradient(135deg, #4facfe, #00f2fe);
            color: white;
        }

        .menu-content {
            flex: 1;
        }

        .menu-title {
            font-size: 15px;
            font-weight: 500;
            color: #333;
            margin-bottom: 2px;
        }

        .menu-subtitle {
            font-size: 12px;
            color: #666;
        }

        .menu-arrow {
            color: #ccc;
            font-size: 16px;
        }

        .info-section {
            margin: 15px;
            background: white;
            border-radius: 12px;
            padding: 15px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
        }

        .info-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 0;
            border-bottom: 1px solid #f0f0f0;
        }

        .info-item:last-child {
            border-bottom: none;
        }

        .info-label {
            font-size: 14px;
            color: #666;
        }

        .info-value {
            font-size: 14px;
            color: #333;
            font-weight: 500;
            text-align: right;
            max-width: 60%;
            word-break: break-all;
        }

        .action-buttons {
            display: flex;
            gap: 10px;
            margin: 15px;
        }

        .btn {
            flex: 1;
            padding: 12px;
            border: none;
            border-radius: 10px;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }

        .btn-primary:active {
            transform: scale(0.98);
        }

        .btn-secondary {
            background: #6c757d;
            color: white;
        }

        .btn-secondary:active {
            background: #5a6268;
        }

        .welcome-message {
            background: linear-gradient(135deg, #e8f5e8 0%, #d4edda 100%);
            border-radius: 12px;
            margin: 15px;
            padding: 15px;
            text-align: center;
        }

        .welcome-message h2 {
            color: #155724;
            font-size: 16px;
            margin-bottom: 8px;
        }

        .welcome-message p {
            color: #155724;
            font-size: 13px;
        }

        .debug-info {
            background: #f8f9fa;
            border-radius: 12px;
            margin: 15px;
            padding: 15px;
            border-left: 4px solid #007bff;
        }

        .debug-info h3 {
            color: #333;
            font-size: 14px;
            margin-bottom: 10px;
        }

        .debug-item {
            display: flex;
            justify-content: space-between;
            margin-bottom: 5px;
            font-size: 11px;
        }

        .debug-label {
            color: #666;
        }

        .debug-value {
            color: #333;
            font-weight: 500;
            max-width: 60%;
            word-break: break-word;
        }

        .status-badge {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 12px;
            font-size: 11px;
            font-weight: 500;
        }

        .status-success {
            background: #d4edda;
            color: #155724;
        }

        .status-info {
            background: #d1ecf1;
            color: #0c5460;
        }

        .content-wrapper {
            padding-bottom: 80px; /* 为底部导航栏留出空间 */
        }

        .bottom-nav {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background: white;
            border-top: 1px solid #e9ecef;
            display: flex;
            justify-content: space-around;
            padding: 8px 0;
            z-index: 1000;
        }

        .nav-item {
            flex: 1;
            text-align: center;
            padding: 8px;
            cursor: pointer;
            transition: all 0.2s ease;
        }

        .nav-item.active {
            color: #667eea;
        }

        .nav-icon {
            font-size: 18px;
            margin-bottom: 1px;
        }

        .nav-label {
            font-size: 10px;
        }

        @media (max-width: 768px) {
            body {
                font-size: 13px;
            }

            .user-card {
                margin: 15px 10px 10px;
                padding: 15px;
            }

            .user-info {
                padding: 8px 0;
            }

            .user-row {
                margin-bottom: 10px;
                padding: 6px 0;
            }

            .user-name {
                font-size: 16px;
            }

            .user-phone {
                font-size: 12px;
                padding: 3px 10px;
            }

            .user-company {
                font-size: 12px;
                padding: 4px 0;
            }

            .menu-section {
                margin: 10px;
            }

            .section-title {
                font-size: 14px;
            }

            .menu-item {
                padding: 12px 15px;
            }

            .menu-icon {
                width: 36px;
                height: 36px;
                font-size: 16px;
            }

            .menu-title {
                font-size: 14px;
            }

            .menu-subtitle {
                font-size: 11px;
            }

            .info-section {
                margin: 10px;
                padding: 12px;
            }

            .info-item {
                padding: 10px 0;
            }

            .info-label,
            .info-value {
                font-size: 12px;
            }

            .action-buttons {
                margin: 10px;
            }

            .btn {
                padding: 10px;
                font-size: 13px;
            }

            .welcome-message,
            .debug-info {
                margin: 10px;
                padding: 12px;
            }

            /* 功能块移动端响应式样式 */
            .function-blocks {
                grid-template-columns: repeat(3, 1fr);
                gap: 6px;
                margin-top: 15px;
                grid-auto-flow: column;
                white-space: nowrap;
            }

            .function-item {
                padding: 12px 10px;
                border-radius: 10px;
            }

            .function-icon {
                font-size: 20px;
                margin-bottom: 6px;
            }

            .function-title {
                font-size: 13px;
                margin-bottom: 3px;
            }

            .function-desc {
                font-size: 10px;
            }
        }

      </style>
</head>
<body>
    <div class="header">
        <h1 id="profileTitle">个人中心</h1>
        <p>管理您的账户和设置</p>
    </div>

    <div class="container">
        <div class="content-wrapper">
            <!-- 欢迎消息 -->
            <div id="welcomeMessage" class="welcome-message" style="display: none;">
                <h2>🎉 欢迎来到个人中心</h2>
                <p id="welcomeText"></p>
            </div>

            <!-- 用户信息卡片 -->
            <div class="user-card">
                <div class="user-info">
                    <div class="user-row">
                        <span class="user-name" id="userName">加载中...</span>
                        <span class="user-phone" id="userPhone">加载中...</span>
                        <span class="user-company" id="companyName">加载中...</span>
                    </div>
                </div>
                
                <div class="function-blocks">
                    <div class="function-item" onclick="handleFunctionClick('new-product')">
                        <div class="function-icon">🚀</div>
                        <div class="function-title">推新品</div>
                        <div class="function-desc">给终端推新品</div>
                    </div>
                    <div class="function-item" onclick="handleFunctionClick('plan')">
                        <div class="function-icon">📋</div>
                        <div class="function-title">报计划</div>
                        <div class="function-desc">采购计划标价</div>
                    </div>
                    <div class="function-item" onclick="handleFunctionClick('agent')">
                        <div class="function-icon">🤝</div>
                        <div class="function-title">招代理</div>
                        <div class="function-desc">招募合作伙伴</div>
                    </div>
                </div>
            </div>

            <!-- 快捷功能 -->
            <div class="menu-section">
                <div class="section-title">快捷功能</div>
                <div class="menu-list">
                    <a href="#" class="menu-item" onclick="handleMenuClick('orders')">
                        <div class="menu-icon blue">📋</div>
                        <div class="menu-content">
                            <div class="menu-title">我的订单</div>
                            <div class="menu-subtitle">查看订单历史和状态</div>
                        </div>
                        <div class="menu-arrow">›</div>
                    </a>
                    <a href="#" class="menu-item" onclick="handleMenuClick('profile')">
                        <div class="menu-icon green">👤</div>
                        <div class="menu-content">
                            <div class="menu-title">个人资料</div>
                            <div class="menu-subtitle">编辑个人信息</div>
                        </div>
                        <div class="menu-arrow">›</div>
                    </a>
                    <a href="#" class="menu-item" onclick="handleMenuClick('security')">
                        <div class="menu-icon orange">🔒</div>
                        <div class="menu-content">
                            <div class="menu-title">账号安全</div>
                            <div class="menu-subtitle">修改密码和安全设置</div>
                        </div>
                        <div class="menu-arrow">›</div>
                    </a>
                    <a href="#" class="menu-item" onclick="handleMenuClick('settings')">
                        <div class="menu-icon purple">⚙️</div>
                        <div class="menu-content">
                            <div class="menu-title">系统设置</div>
                            <div class="menu-subtitle">偏好设置和通知</div>
                        </div>
                        <div class="menu-arrow">›</div>
                    </a>
                </div>
            </div>

            <!-- 账户信息 -->
            <div class="menu-section">
                <div class="section-title">账户信息</div>
                <div class="info-section">
                    <div class="info-item">
                        <div class="info-label">手机号码</div>
                        <div class="info-value" id="userPhone">-</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">微信ID</div>
                        <div class="info-value" id="muserid">-</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">买家ID</div>
                        <div class="info-value" id="buserid">-</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">账户状态</div>
                        <div class="status-badge status-success" id="userStatus">已认证</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">注册时间</div>
                        <div class="info-value" id="registerTime">-</div>
                    </div>
                </div>
            </div>

            <!-- 操作按钮 -->
            <div class="action-buttons">
                <button class="btn btn-primary" onclick="editProfile()">编辑资料</button>
                <button class="btn btn-secondary" onclick="logout()">退出登录</button>
            </div>

            <!-- 调试信息 -->
            <div class="debug-info">
                <h3>🔍 调试信息</h3>
                <div class="debug-item">
                    <span class="debug-label">Flag:</span>
                    <span class="debug-value" id="debugFlag">-</span>
                </div>
                <div class="debug-item">
                    <span class="debug-label">Auto Login:</span>
                    <span class="debug-value" id="debugAutoLogin">-</span>
                </div>
                <div class="debug-item">
                    <span class="debug-label">Registration:</span>
                    <span class="debug-value" id="debugRegistration">-</span>
                </div>
                <div class="debug-item">
                    <span class="debug-label">URL参数:</span>
                    <span class="debug-value" id="debugParams">-</span>
                </div>
            </div>
        </div>
    </div>

    <!-- 底部导航 -->
    <div class="bottom-nav">
        <div class="nav-item" onclick="handleNavClick('home')">
            <div class="nav-icon">🏠</div>
            <div class="nav-label">首页</div>
        </div>
        <div class="nav-item" onclick="handleNavClick('dashboard')">
            <div class="nav-icon">📊</div>
            <div class="nav-label">控制台</div>
        </div>
        <div class="nav-item" onclick="handleNavClick('features')">
            <div class="nav-icon">🔧</div>
            <div class="nav-label">功能</div>
        </div>
        <div class="nav-item active" onclick="handleNavClick('profile')">
            <div class="nav-icon">👤</div>
            <div class="nav-label">我的</div>
        </div>
    </div>

    <script>
        // 测试JavaScript是否运行
        console.log('🧪 JavaScript开始执行 - profile.html');
        
        class ProfilePage {
            constructor() {
                console.log('🔧 ProfilePage 构造函数被调用');
                this.urlParams = new URLSearchParams(window.location.search);
                console.log('📄 URL参数字符串:', window.location.search);
                this.params = {}; // 初始化params对象
                this.parseUrlParams(); // 先解析URL参数
                console.log('📋 解析后的参数:', this.params);
                this.userData = this.generateUserData(); // 然后生成用户数据
                console.log('👤 用户数据生成完成:', this.userData);
            }

            async init() {
                console.log('🚀 ProfilePage init 方法被调用');
                await this.loadCompanyData();
                console.log('📊 公司数据加载完成，继续初始化...');
                this.displayUserInfo();
                this.showWelcomeMessage();
                this.updateDebugInfo();
                this.loadUserStats();
                console.log('✅ ProfilePage 初始化完成');
            }

            parseUrlParams() {
                // 解析URL参数
                console.log('🔍 parseUrlParams被调用');
                console.log('🔍 URLSearchParams对象:', this.urlParams);
                
                // 逐个检查参数
                const muserid = this.urlParams.get('muserid');
                const buserid = this.urlParams.get('buserid');
                const flag = this.urlParams.get('flag');
                
                console.log('🔍 muserid:', muserid);
                console.log('🔍 buserid:', buserid);
                console.log('🔍 flag:', flag);
                
                this.params = {
                    muserid: muserid,
                    buserid: buserid,
                    flag: flag,
                    auto_login: this.urlParams.get('auto_login'),
                    registration: this.urlParams.get('registration'),
                    name: this.urlParams.get('name'),
                    company: this.urlParams.get('company'),
                    phone: this.urlParams.get('phone')
                };

                console.log('✅ 解析到的URL参数:', this.params);
            }

            generateUserData() {
                // 优先从认证管理器获取真实用户数据
                if (window.authManager && window.authManager.isLoggedIn()) {
                    const authUserData = window.authManager.getUserInfo();
                    if (authUserData && authUserData.name) {
                        return {
                            name: authUserData.name || this.params.name,
                            company: authUserData.company || this.params.company,
                            phone: authUserData.phone || this.params.phone || this.generateRandomPhone(),
                            muserid: authUserData.muserid || this.params.muserid,
                            buserid: authUserData.buserid || this.params.buserid,
                            registerTime: this.generateRandomDate(),
                            status: (authUserData.flag === 'Y' || authUserData.status === 'Y') ? '已认证 (Flag=Y)' : '已认证'
                        };
                    }
                }
                
                // 生成模拟用户数据（备用方案）
                const names = ['张三', '李四', '王五', '赵六', '钱七', '孙八'];
                
                const randomName = names[Math.floor(Math.random() * names.length)];
                
                return {
                    name: this.params.name || randomName,
                    company: this.params.company,
                    phone: this.params.phone || this.generateRandomPhone(),
                    muserid: this.params.muserid || this.generateRandomId(),
                    buserid: this.params.buserid || this.generateRandomId(),
                    registerTime: this.generateRandomDate(),
                    status: '已认证'
                };
            }

            generateRandomPhone() {
                const prefix = ['138', '139', '136', '137', '135', '186', '159', '158'];
                const randomPrefix = prefix[Math.floor(Math.random() * prefix.length)];
                const randomNumber = Math.floor(Math.random() * 100000000).toString().padStart(8, '0');
                return randomPrefix + randomNumber;
            }

            generateRandomId() {
                return Math.floor(Math.random() * 1000000000000000000).toString();
            }

            generateRandomDate() {
                const start = new Date(2023, 0, 1);
                const end = new Date();
                const randomDate = new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
                return randomDate.toLocaleDateString('zh-CN');
            }

            formatPhoneNumber(phone) {
                if (!phone) return '未设置';
                
                // 移除非数字字符
                const cleaned = phone.replace(/\D/g, '');
                
                // 检查是否为11位手机号
                if (cleaned.length === 11) {
                    return cleaned.replace(/(\d{3})(\d{4})(\d{4})/, '$1 $2 $3');
                }
                
                // 如果不是11位，原样返回
                return phone;
            }

            displayUserInfo() {
                // 显示用户信息
                document.getElementById('userName').textContent = this.userData.name;
                document.getElementById('companyName').textContent = this.userData.company;
                
                // 格式化电话号码显示
                const formattedPhone = this.formatPhoneNumber(this.userData.phone);
                document.getElementById('userPhone').textContent = formattedPhone;
                document.getElementById('muserid').textContent = this.userData.muserid;
                document.getElementById('buserid').textContent = this.userData.buserid;
                document.getElementById('registerTime').textContent = this.userData.registerTime;
                
                // 设置状态
                const statusBadge = document.getElementById('userStatus');
                if (this.params.flag === 'Y') {
                    statusBadge.textContent = '已认证 (Flag=Y)';
                    statusBadge.className = 'status-badge status-success';
                } else if (this.params.registration === 'success') {
                    statusBadge.textContent = '新注册用户';
                    statusBadge.className = 'status-badge status-info';
                } else {
                    statusBadge.textContent = '已认证';
                    statusBadge.className = 'status-badge status-success';
                }
                
                // 更新页面标题为公司名称+采购中心
                this.updateProfileTitle();
            }

            async loadCompanyData() {
                // 🚨 重要调试信息
                console.log('🚨🚨🚨 loadCompanyData方法被调用了！🚨🚨🚨');
                
                // 如果有buserid参数，调用API获取公司信息
                console.log('=== 开始加载公司数据 ===');
                console.log('当前URL:', window.location.href);
                console.log('URL参数:', this.params);
                console.log('buserid值:', this.params.buserid);
                
                if (this.params.buserid) {
                    try {
                        // 直接构建完整的API URL
                        const fullUrl = `http://dadefeng.com/srmddf/company/buysite?id=${this.params.buserid}`;
                        
                        console.log('🚀 正在请求公司数据...');
                        console.log('📡 请求URL:', fullUrl);
                        
                        // 使用简单的GET请求，不需要特殊headers
                        const response = await fetch(fullUrl);
                        
                        console.log('📊 响应状态:', response.status);
                        console.log('📋 响应状态文本:', response.statusText);
                        
                        if (response.ok) {
                            const data = await response.json();
                            console.log('✅ API响应成功:', data);
                            
                            // 检查API响应结构
                            if (data && data.result && data.result.companyname) {
                                // 更新用户数据中的公司信息
                                this.userData.company = data.result.companyname;
                                console.log('🎯 公司名称已提取:', this.userData.company);
                                
                                // 立即更新页面标题
                                this.updateProfileTitle();
                                console.log('🏆 页面标题更新完成');
                            } else {
                                console.log('❌ 公司名称字段未找到');
                                console.log('📄 完整响应结构:', JSON.stringify(data, null, 2));
                            }
                        } else {
                            console.log('❌ API请求失败');
                            console.log('📊 状态码:', response.status);
                            console.log('📝 状态文本:', response.statusText);
                            
                            // 尝试读取错误响应
                            try {
                                const errorText = await response.text();
                                console.log('💥 错误响应:', errorText);
                            } catch (e) {
                                console.log('💥 无法读取错误响应');
                            }
                        }
                    } catch (error) {
                        console.log('❌ 请求异常');
                        console.log('💥 错误类型:', error.name);
                        console.log('💥 错误信息:', error.message);
                        
                        // 检查是否是CORS错误
                        if (error.name === 'TypeError' && error.message.includes('Failed to fetch')) {
                            console.log('🚫 这可能是CORS跨域问题，请检查服务器配置');
                        }
                    }
                } else {
                    console.log('❌ buserid参数不存在');
                    console.log('📄 当前URL参数:', window.location.search);
                }
                console.log('=== 公司数据加载完成 ===');
            }

            updateProfileTitle() {
                const profileTitle = document.getElementById('profileTitle');
                console.log('updateProfileTitle 被调用');
                console.log('当前公司数据:', this.userData.company);
                
                if (this.userData.company && this.userData.company !== '未设置' && this.userData.company !== '') {
                    profileTitle.textContent = this.userData.company + '采购中心';
                    console.log('页面标题已更新为:', this.userData.company + '采购中心');
                } else {
                    profileTitle.textContent = '个人中心';
                    console.log('使用默认标题: 个人中心');
                }
            }

            loadUserStats() {
                // 用户统计数据功能暂时禁用（对应的HTML元素不存在）
                console.log('用户统计数据功能已禁用');
            }

            displayStats(stats) {
                // 统计数据显示功能暂时禁用（对应的HTML元素不存在）
                console.log('统计数据动画功能已禁用');
            }

            animateValue(elementId, start, end, duration) {
                const element = document.getElementById(elementId);
                
                // 检查元素是否存在
                if (!element) {
                    console.warn('Element not found for animation:', elementId);
                    return;
                }
                
                const increment = (end - start) / (duration / 16);
                let current = start;
                
                const timer = setInterval(() => {
                    current += increment;
                    if (current >= end) {
                        current = end;
                        clearInterval(timer);
                    }
                    
                    element.textContent = Math.floor(current).toLocaleString();
                }, 16);
            }

            showWelcomeMessage() {
                const welcomeDiv = document.getElementById('welcomeMessage');
                const welcomeText = document.getElementById('welcomeText');
                
                if (this.params.flag === 'Y') {
                    welcomeDiv.style.display = 'block';
                    welcomeText.textContent = '检测到您的认证状态，已自动登录到个人中心';
                } else if (this.params.registration === 'success') {
                    welcomeDiv.style.display = 'block';
                    welcomeText.textContent = '恭喜您注册成功！欢迎加入我们的平台';
                } else if (this.params.auto_login === 'true') {
                    welcomeDiv.style.display = 'block';
                    welcomeText.textContent = '欢迎回来！已为您自动登录';
                } else {
                    welcomeDiv.style.display = 'none';
                }
            }

            updateDebugInfo() {
                // 更新调试信息
                document.getElementById('debugFlag').textContent = this.params.flag || '-';
                document.getElementById('debugAutoLogin').textContent = this.params.auto_login || '-';
                document.getElementById('debugRegistration').textContent = this.params.registration || '-';
                
                const paramsStr = Object.entries(this.params)
                    .filter(([key, value]) => value)
                    .map(([key, value]) => `${key}=${value}`)
                    .join('&');
                document.getElementById('debugParams').textContent = paramsStr || '-';
            }
        }

        // 功能块点击处理
        function handleFunctionClick(functionType) {
            console.log('Function clicked:', functionType);
            
            switch(functionType) {
                case 'new-product':
                    alert('推新品功能开发中...');
                    break;
                case 'plan':
                    alert('报计划功能开发中...');
                    break;
                case 'agent':
                    alert('招代理功能开发中...');
                    break;
            }
        }

        // 页面功能函数
        function handleMenuClick(action) {
            console.log('Menu clicked:', action);
            
            switch(action) {
                case 'orders':
                    alert('我的订单功能开发中...');
                    break;
                case 'profile':
                    editProfile();
                    break;
                case 'security':
                    alert('账号安全功能开发中...');
                    break;
                case 'settings':
                    alert('系统设置功能开发中...');
                    break;
            }
        }

        function editProfile() {
            alert('编辑资料功能开发中...');
        }

        function logout() {
            if (confirm('确定要退出登录吗？')) {
                // 跳转到注册页面
                window.location.href = 'index.html';
            }
        }

        // 导航处理
        function handleNavClick(nav) {
            console.log('Nav clicked:', nav);
            
            switch(nav) {
                case 'home':
                    // 跳转到首页时带上当前参数
                    const profilePage = window.profilePageInstance;
                    let homeUrl = 'home.html';
                    
                    if (profilePage && profilePage.params && profilePage.params.buserid) {
                        homeUrl += `?buserid=${profilePage.params.buserid}`;
                        if (profilePage.params.muserid) {
                            homeUrl += `&muserid=${profilePage.params.muserid}`;
                        }
                        if (profilePage.params.flag) {
                            homeUrl += `&flag=${profilePage.params.flag}`;
                        }
                    }
                    
                    window.location.href = homeUrl;
                    break;
                case 'dashboard':
                    window.location.href = 'dashboard.html';
                    break;
                case 'features':
                    window.location.href = 'features.html';
                    break;
                case 'profile':
                    // 当前页面，不需要跳转
                    break;
            }
        }

        // 初始化页面
        document.addEventListener('DOMContentLoaded', async () => {
            console.log('🌟 DOM内容已加载，开始初始化ProfilePage');
            const profilePage = new ProfilePage();
            console.log('📱 ProfilePage实例已创建，调用init方法');
            await profilePage.init();
            console.log('🎉 ProfilePage初始化流程完成');
            
            // 保存实例到全局变量，供其他函数使用
            window.profilePageInstance = profilePage;
        });
    </script>
    
    <!-- 认证系统 -->
    <script src="auth.js"></script>
    <script src="api.js"></script>
    <script src="router.js"></script>
</body>
</html>